package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.common.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品请求处理层
 * @author zgp
 * @version V1.0
 * @date 2025-01-14 15:57
 */
@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品管理")
@Slf4j
public class DishController {
    @Autowired
    private DishService dishService;

    @PostMapping
    @ApiOperation("菜品新增")
    public Result<String> addDish(@RequestBody DishDTO dishDTO){
        log.info("菜品新增，dishDTO：{}", dishDTO);
        dishService.addDish(dishDTO);
        return Result.success(MessageConstant.ADD_SUCCESS);
    }

    @GetMapping("/page")
    @ApiOperation("菜品条件分页查询")
    public Result<PageResult<DishVO>> pageList(DishPageQueryDTO dishPageQueryDTO){
        log.info("菜品条件分页查询，dishPageQueryDTO：{}", dishPageQueryDTO);
        return Result.success(dishService.getPageList(dishPageQueryDTO));
    }

    @DeleteMapping
    @ApiOperation("菜品删除")
    public Result<String> deleteDish(@RequestParam("ids") List<Integer> ids){
        log.info("菜品删除，ids：{}", ids);
        dishService.deleteByIds(ids);
        return Result.success(MessageConstant.DELETE_SUCCESS);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启售/停售菜品")
    public Result<String> enableOrDisableDish(@PathVariable Integer status, Long id){
        log.info("启售/停售菜品，id：{}，status：{}", id, status);
        dishService.enableOrDisableDishStatus(status, id);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }

    @PutMapping
    @ApiOperation("修改菜品")
    public Result<String> modifyDish(@RequestBody DishDTO dishDTO){
        log.info("修改菜品，dishDTO：{}", dishDTO);
        dishService.updateDish(dishDTO);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品")
    public Result<DishVO> getDishById(@PathVariable Long id){
        log.info("根据id查询菜品，id：{}", id);
        return Result.success(dishService.getDishById(id));
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result<List<DishVO>> getDishByCategoryId(Integer categoryId){
        log.info("根据分类id查询菜品，categoryId：{}", categoryId);
        return Result.success(dishService.getDishByCategoryId(categoryId));
    }
}
